<%
if semester_obj != nil
  semester = semester_obj.id
  #FIXME - should be first line
  current_cis_semester = course.cis_semesters.find(:first, :conditions => ['year = ? AND semester = ?', semester_obj.year, semester_obj.semester])
  #current_cis_semester = course.cis_semesters[0]
else
  semester = -1
end
-%>
<div class="course" id="<%= "coursediv_#{semester}_#{course.id}" %>" style="<% if effect %>display:none;<% end%>">
    <div class="course_code <% if !course.dependencies_satisfied(semester, session[:user]) %>needs_prereq<%end%>" >
    <% if session[:user] == @user.id -%>
        <%= link_to('X', :action => "remove", :course_id => course.id, :semester_id => semester) -%>
    <% end -%>
        <%= course.cis_subject.code %> <%= course.number %> <%= link_to_function 'sections>', visual_effect(:toggle_blind, "sects_#{semester}_#{course.id}"), :class => 'sections_link' %>
    </div>
    <div class="course_desc"><%= course.title %></div>
    <div class="title">Prerequisites:</div>
    <div class="course_prerequisites">
        <%= course.course_dependency.to_s %>
    </div>
    <div class="title">Friends Sharing:</div>
    <div class="course_sharing">
        <ul>
        <% course.iterate_users_semesters(@user) do |shared_id,friend,friend_semester| %>
           <li><%= if session[:user] == @user.id
                    link_to 'X', {:action => 'delete_shared_course', :id => shared_id},
                        {:confirm => "Are you sure that you do not want to take this course with this friend?",
                         :title => "Do not take this course with this friend"}
                   end %>
                   <%= friend.to_s %> - <%= friend_semester.to_s %></li>
        <% end %>
        </ul>
        <%= link_to 'Take with friend', :action => 'take_course_with_friend', :course_id => course.id, :friend_id => @user.id, :semester_id => semester %>
    </div>
    <div class="links">
        <a href="http://courses.uiuc.edu/cis/catalog/urbana/<%= lookup_year(Time.now) %>/<%= lookup_semester_word(Time.now) %>/<%= course.cis_subject.code %>/<%= course.number %>.html" target="_blank">Course info</a>
        
        <% if course.cis_semesters.find_by_year_and_semester(lookup_year(Time.now),lookup_semester(Time.now)) != nil -%>
            | <a href="http://courses.uiuc.edu/cis/schedule/urbana/<%= lookup_year(Time.now) %>/<%= lookup_semester_word(Time.now) %>/<%= course.cis_subject.code %>/<%= course.number %>.html" target="_blank" >Section schedule</a>
        <% end %>
        | <a href="http://www.coursefire.com/view_stats.php?courseID=<%= course.cis_subject.code + course.number.to_s %>" target="_blank" > Coursefire Page</a>
   </div>
   <div style='display:none' class='sections_list' id='<%="sects_#{semester}_#{course.id}"%>'>
      <% if current_cis_semester -%>
         <%= render :partial => 'section_choice', :collection => current_cis_semester.cis_sections, :locals => {:semester => semester} %>
      <% end -%>      
   </div>
</div>

<% if session[:user] == @user.id %>
  <% if effect %>
  <script language="javascript" type="text/javascript">
      <%= visual_effect :blind_down, "coursediv_#{semester}_#{course.id}" %>
  </script>
  <% end %>

  <%= draggable_element "coursediv_#{semester}_#{course.id}", :revert => true %>
<% end %>
